<template>
  <!-- appendToBody -->
  <el-dialog
    :append-to-body="appendToBody"
    :title="TextUtilsTitle"
    :visible.sync="addText"
    @close="handleDialogClose"
    :close-on-click-modal="false"
  >
  <!-- computedtransmitVal -->
    <el-input
      type="textarea"
      v-model="globalText"
      show-word-limit
      :maxlength="mainOption.globalOptionText.contentTextMax"
      :autosize="mainOption.globalOptionText.autosize"
      clearable
      v-if="!isUpdata"
    ></el-input>
    <!--  -->
    <el-input
      type="textarea"
      v-model="transmitVal.val"
      show-word-limit
      :maxlength="mainOption.globalOptionText.contentTextMax"
      :autosize="mainOption.globalOptionText.autosize"
      @input="oninput($event)"
      clearable
      v-else
    ></el-input>
    <div slot="footer" class="dialog-footer">
      <el-button @click="gloablTextCancel">取 消</el-button>
      <el-button type="primary" @click="gloablTextConfirm">确 定</el-button>
    </div>
  </el-dialog>
</template>
<script>
module.exports = {
  data() {
    return {
      compName: 'dialogTextEdit',
      addText: false,
      globalText: ""
    };
  },
  props: {
    mainOption: {
      type: Object,
      default: () => {
        return {}
      }
    },
    stepIndex: {
      type: Number,
      default: 0
    },
    isUpdata: {
      type: Boolean,
      default: false
    },
    // 传来的值
    transmitVal: {
      type: Object,
      default: () => {
        return {}
      }
    },
    // tit
    TextUtilsTitle: {
      type: String,
      default: ""
    },
    // 
    appendToBody: {
      type: Boolean,
      defaule: false
    }
  },
  methods: {
    oninput(e){
      this.$set(this.transmitVal, 'val', e)
    },
    //
    handleDialogClose() {
      this.addText = false;
      this.globalText = "";
    },
    // 取消
    gloablTextCancel() {
      if (this.isUpdata) {
        this.addText = false;
        this.$emit("text-edit-cancel-transmit");
      } else {
        this.addText = false;
        this.globalText = "";
      }
    },
    // 确认
    gloablTextConfirm() {
      if (this.isUpdata) {
        this.addText = false;
        this.$emit("text-edit-updata-transmit", this.transmitVal.val);
      } else {
        this.addText = false;
        this.$emit("text-edit-transmit", this.globalText);
        this.globalText = "";
      }
    }
  }
};
</script>
<style scoped>
</style>